package com.zhiwei.controller;

import com.zhiwei.pojo.Products;
import com.zhiwei.service.ProductsService;
import com.zhiwei.vo.PageResult;
import com.zhiwei.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/products")
public class ProductsController {
    @Autowired
    private ProductsService productsService;
    @GetMapping("/allList")
    public SysResult getProductLists(){
        List<Products> products = productsService.getProductLists();
        return SysResult.success(products);
    }
    @GetMapping("/list")
    public SysResult getProductList(PageResult pageResult){
        PageResult products = productsService.getProductList(pageResult);
        return SysResult.success(products);
    }
    @PutMapping ("/updateproducts")
    public SysResult updateproducts(@RequestBody Products products){
        productsService.updateproducts(products);
        return SysResult.success();
    }
    @PutMapping("/updatestatus/{id}/{status}")
    public SysResult updatestatus(Products products){
        productsService.updatestatus(products);
        return SysResult.success();
    }
    @DeleteMapping("/{id}")
    public SysResult deleteproducts(@PathVariable Integer id){
        productsService.deleteproducts(id);
        return SysResult.success();
    }
    @PostMapping("/insertproducts")
    public SysResult intertproducts(@RequestBody Products products){
        productsService.intertproducts(products);
        return SysResult.success();
    }
}
